package main.java.com.example.demo.controller;

import com.example.demo.pojo.Cart;
import com.example.demo.service.CartService;
import com.example.demo.vo.CartVo;
import com.example.demo.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Param:
 * @Author:
 * @Date:
 */
@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    /**
     * 查询全部购物车
     */
    @PostMapping("/findCart")
    public RespBean findCart(@RequestBody Cart cart){
        List<CartVo> cartVoList = cartService.findCart(cart);
        return RespBean.success("200", "查询成功", cartVoList);
    }
    /**
     * 加入购物车
     * @param cart
     * @return
     */
    @PostMapping("/insertGoodIntoCart")
    public RespBean insertGoodIntoCart(@RequestBody Cart cart){
        cartService.insertGoodIntoCart(cart);
        return RespBean.success("200", "加入购物车成功", null);
    }

    /**
     * 删除购物车
     */
    @PostMapping("/delCart")
    public RespBean delCart(@RequestBody Cart cart){
        cartService.delCart(cart);
        return RespBean.success("200", "删除成功", null);
    }
}
